import { GetLoginApi, getseatchApi, alltaskApi, getUserInfoApi } from '@/api'
export default {
  namespaced: true,
  state: {
    token: '',
    userName: '',
    regionId: {},
    goodlist: [],
    alltask: [],
    userName1: ''

  },
  mutations: {
    changeToken(state, val) {
      state.token = val
    },
    changeName(state, val) {
      state.userName = val
    },
    region(state, val) {
      state.regionId = val
    },
    goodlistAdd(state, val) {
      state.goodlist = val
    },
    // 获取工单状态
    getchanggealltask(state, val) {
      state.alltask = val
    },
    getuesr(state, val) {
      state.userName1 = val
    }
  },
  actions: {
    async GetTokenLogin({ commit }, val) {
      const { data } = await GetLoginApi(val)
      commit('changeToken', data.token)
      commit('changeName', data.userName)
      commit('region', data)
      await getUserInfoApi(1)
      if (data.msg !== '登录成功') {
        return Promise.reject(data.msg)
      }
    },
    async getseatchAp({ commit }, val) {
      const { data } = await getseatchApi(val)
      commit('goodlistAdd', data)
    },
    async getalltask({ commit }, val) {
      const { data } = await alltaskApi()
      commit('getchanggealltask', data)
    },
    tuilogin({ commit }) {
      commit('changeToken', '')
    }
  }
}
